﻿using SRB.Tg.DrawingStandard;
using System;
using System.Collections.Generic;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class Pile : MemberBase
    {
        double D;
        PileParameter pileParameter;
        System.Data.DataTable dtRebar;
        public Pile(double d, double l)
        {
            D = d;           
        }

        public Pile(PileParameter para)
        {
            //D = d;
            //L = l;
            pileParameter = para;
            D = para.pile_diameter;
            
        }
        public void DrawingPile(Database db, int OverAllScale ,System.Data.DataTable dt1, System.Data.DataTable dt2)
        {
            if(dt1.Rows.Count>0)
            {
                dtRebar = dt1;
            }
            #region 绘制图形
            Extents2d ExtPile, ExtLPile, ExtCPile, ExtDetail;
            Point2d RefPtPile, RefPtLPile, RefPtCPile, RefPtDetail;
            RefPtPile = Point2d.Origin;
            RefPtLPile = RefPtPile.C2D(420 * 0.5 * OverAllScale );
            RefPtCPile = RefPtLPile.C2D(420 * 0.5 * OverAllScale);
            RefPtDetail = RefPtCPile.C2D(420 * 0.5 * OverAllScale);

            PlotPile(ref db, out ExtPile, RefPtPile, OverAllScale);
            //BaseShapePloter.RenderEntity(db, ExtPile.ConvertPL());

            PlotLPile(ref db, out ExtLPile, RefPtLPile, OverAllScale);
            //BaseShapePloter.RenderEntity(db, ExtLPile.ConvertPL());

            PlotCPile(ref db, out ExtCPile, RefPtCPile, OverAllScale);
            //BaseShapePloter.RenderEntity(db, ExtCPile.ConvertPL());

            RendeDetail(ref db, RefPtDetail, out ExtDetail, dt1, dt2, OverAllScale);
            #endregion

            #region 模型空间到布局空间投影处理
            LayoutTools.CreatePileLayout(db, "图纸", ExtPile, ExtLPile, ExtCPile, ExtDetail, Extensions.leftWidth, 5, Extensions.bottomHeight, 10, OverAllScale);
            #endregion
        }

        private void PlotPile(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.AddTitle(db, insertPoint, ref ext, "ELEVATION", "", scale);
            double tH = Math.Abs(double.Parse(pileParameter.top_size.Split(',')[0]));
            double tL = Math.Abs(double.Parse(pileParameter.top_size.Split(',')[1]));
            double bH =Math.Abs( double.Parse(pileParameter.bottom_size.Split(',')[0]));
            double bL = Math.Abs(double.Parse(pileParameter.bottom_size.Split(',')[1]));
            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -30 * scale);
            double SheetLength = 297;
            if (Extensions.curMapSheet =="A3")
                SheetLength = 297-10-20-70;
            else
                SheetLength = 594 - 10 - 30-90;
            //PLPloter.AddPloy4(db, ref ext, M1, 0.5 * D, 0.5 * D, SheetLength*scale+230);
            List<double> listTop = new List<double>();
            
            List<Point3d> listPt = SteelBar.calculatePileSteelElevationCoordinate(M1.C3D(), pileParameter.main_reinforcement_number, 0.5 * (D - 2*pileParameter.concreteProtectLayer), 30,ref listTop);
           
            #region  图形绘制

            #region 上半部分边框绘制
            PLPloter.AddLine(db, M1.C2D(-0.5 * D), M1.C2D(-0.5 * D - 15*scale), ref ext, "H细线");
            RebarPLPloter.CreateBreakLine(db, ref ext, M1.C2D(-0.5 * D - 15 * scale,1200+10*20 + 8 * scale), M1.C2D(-0.5 * D - 15 * scale), scale);
            RebarPLPloter.CreateBreakLine(db, ref ext, M1.C2D(-0.5 * D - 15 * scale, 1200 + 10 * 20+8*scale), M1.C2D(0.5 * D + 15 * scale, 1200 + 10 * 20 + 8 * scale), scale);
            RebarPLPloter.CreateBreakLine(db, ref ext, M1.C2D(0.5 * D + 15 * scale, 1200 + 10 * 20 + 8 * scale), M1.C2D(0.5 * D + 15 * scale), scale);
            PLPloter.AddLine(db, M1.C2D(0.5 * D), M1.C2D(0.5 * D + 15 * scale), ref ext, "H细线");
            PLPloter.AddLine(db, M1.C2D(-0.5 * D), M1.C2D(-0.5 * D,-SheetLength * scale / 2), ref ext, "H细线");
            //PLPloter.CreateBreakLine(db, ref ext, M1.C2D(-0.5 * D-2*scale, -SheetLength * scale / 2), M1.C2D(0.5 * D+ 2 * scale, -SheetLength * scale / 2), scale);
            PLPloter.AddLine(db, M1.C2D(0.5 * D), M1.C2D(0.5 * D, -SheetLength * scale / 2), ref ext, "H细线");
            #endregion

            #region  上半部分绘制
            PLPloter.AddLine(db, M1.C2D(-0.5 * D), M1.C2D(-0.5 * D, 15 * 10), ref ext, "H细线");
            PLPloter.AddLine(db, M1.C2D(-0.5 * D, 15 * 10), M1.C2D(0.5 * D,15 * 10), ref ext, "H细线");
            PLPloter.AddLine(db, M1.C2D(0.5 * D), M1.C2D(0.5 * D, 15 * 10), ref ext, "H细线");

            SteelBar.DrawUpperRebarGrid(db, ref ext, M1, listPt, 0.5 * D - pileParameter.concreteProtectLayer, tH, pileParameter.top_encryption_spacing, tH,bL);
            SteelBar.DrawRebarGrid(db, ref ext, M1, listPt, 0.5 * D - pileParameter.concreteProtectLayer, SheetLength * scale*0.5, pileParameter.standard_spacing, 0.5*D);
            #endregion

            #region 下半部分边框绘制
            Point2d PtBt = M1.C2D(0, -SheetLength * scale *0.5 - 800);
            //PLPloter.CreateBreakLine(db, ref ext, PtBt.C2D(-0.5 * D - 2 * scale, 0), PtBt.C2D(0.5 * D +2 * scale, 0), scale);
            PLPloter.AddLine(db,PtBt.C2D(-0.5 * D, 0), PtBt.C2D(-0.5 * D, -SheetLength * scale * 0.5 - 20*10), ref ext, "H粗线");
            PLPloter.AddLine(db, PtBt.C2D(-0.5 * D, -SheetLength * scale * 0.5- 20 * 10), PtBt.C2D(0.5 * D, -SheetLength * scale * 0.5 - 20 * 10), ref ext, "H粗线");
            PLPloter.AddLine(db,PtBt.C2D(0.5 * D), PtBt.C2D(0.5 * D, -SheetLength * scale * 0.5 - 20 * 10), ref ext, "H粗线");
            #endregion

            #region  下半部分绘制
            double H = -SheetLength * scale / 2 - 800 - 100 * 8- SheetLength * scale * 0.5 * 0.3-100*8;
            PLPloter.AddLine(db, M1.C2D(-0.5 * D + pileParameter.concreteProtectLayer, H), M1.C2D(0.5 * D - pileParameter.concreteProtectLayer, H), ref ext, "H粗线");

            List<Point3d> listBottom = new List<Point3d>();
            for(int i=0;i< listPt.Count;i++)
            {
                listBottom.Add(listPt[i].C3D(0, -SheetLength * scale / 2 - 800));
            }
            SteelBar.DrawBottomRebarGrid(db, ref ext, M1.C2D(0, -SheetLength * scale / 2 - 800), listBottom, 0.5 * D - pileParameter.concreteProtectLayer, SheetLength * scale * 0.5, 100,1000,100,false,15, 0.5 * D);
            Point2d ptTopEnd;
            SteelBar.CreatePartSteelBar(db, ref ext, out ptTopEnd, M1.C2D(0, -SheetLength * scale / 2 - 800 - 100*15), 0.5 * D - pileParameter.concreteProtectLayer, SheetLength * scale*0.5*0.3, 100, scale, true);
            SteelBar.CreateChangePartSteelBar(db, ref ext, M1.C2D(0, -SheetLength * scale / 2 - 800 - SheetLength * scale * 0.5 + SheetLength * scale / 5), 0.5 * (D - 100), SheetLength * scale/5, 100, scale, 1000, 100);
            #endregion

            #region 大样
       
            Point2d ptDYT = M1.C2D(0.5 * D+30*scale);
            Point2d ptDYB = M1.C2D(0.5 * D + 30 * scale, -SheetLength * scale / 2 - 800 - SheetLength * scale * 0.5 + bH);
            
   
            SteelBar.DrawDetails(db, ref ext, scale, ptDYT, ptDYB, tH, tL, bH, bL);

            System.Data.DataRow[] drs = dtRebar.Select("no=1");
            string noS = drs[0]["number"].ToString()+ "Ф" + drs[0]["diameter"].ToString();
            string valueS = (double.Parse(drs[0]["length"].ToString())/10).ToString();
            RebarDimPloter.RebarWire(db, ref ext, ptDYT.C2D(0, -80*scale), noS, valueS, 1,
            GeTools.DegreeToRadian(0), Extensions.curFont, scale);
            #endregion
            #endregion
            #region  编号
            double width = 0;
            int num =(int)( tH / tL);
            List<double> lList = new List<double>();
            for (int i = 0; i < num; i++)
            {
                lList.Add(tL);
            }
            //4
            RebarPLPloter.CreateLineArrowDBNew(db, ref ext, M1.C3D(0, 20 * 10 + tH), ArrowDirection.South, lList, new List<double>(), "4", scale, true, 2,5*scale);

          
            num = (int)(SheetLength * scale * 0.5 / pileParameter.standard_spacing);
            lList = new List<double>();
            lList.Add(100);
            lList.Add(100);
            for (int i = 0; i < num-1; i++)
            {
                lList.Add(pileParameter.standard_spacing);
            }
            double h = SheetLength * scale * 0.5 - num * pileParameter.standard_spacing;
            for (int i = 1; i < 15; i++)
            {
                if(i==1)
                    lList.Add(100*2+800+ h);
                else
                    lList.Add(pileParameter.standard_spacing);
            }
            drs = dtRebar.Select("no=6");
            if (drs.Length > 0)
            {
                //5
                RebarPLPloter.CreateLineArrowDBNew(db, ref ext, M1.C3D(-5 * scale, 20 * 10), ArrowDirection.South, lList, new List<double>(), "6", scale, true, 2, D * 0.5 + 10 * scale);
            }

            //2/3
            RebarPLPloter.CreateLineArrowDBNew(db, ref ext, M1.C3D(5 * scale, -50 * 10 - 200 * 10), ArrowDirection.North, new List<double>(), new List<double>(), "2", scale, true, 2, D * 0.5);

            //3
            RebarPLPloter.CreateLineArrowDBNew(db, ref ext, M1.C3D(5 * scale, H), ArrowDirection.South, new List<double>(), new List<double>(), "3", scale, true, 2, D * 0.5);
            //6
            RebarPLPloter.CreateLineArrowDBNew(db, ref ext, M1.C3D(5 * scale, -SheetLength * scale / 2 - 800 - SheetLength * scale * 0.5 + SheetLength * scale / 5), ArrowDirection.South, new List<double>(), new List<double>(), "5", scale, true, 2, D * 0.5);

            lList = new List<double>();
            //listTop.Insert(0, 0.5 * D - pileParameter.concreteProtectLayer);
            //listTop.Add(0.5 * D - pileParameter.concreteProtectLayer);
            for (int i=0;i<listTop.Count-1;i++)
            {
                 if(i< 4&&i<listTop.Count-1)
                {
                   
                    if (i == listTop.Count / 2-1)
                        lList.Add(Math.Abs(listTop[i + 1] + listTop[i]));
                    else
                       lList.Add(Math.Abs(listTop[i + 1] - listTop[i]));
                }
                else if(i>listTop.Count-4-1 && i < listTop.Count - 1)
                {
                    if (i == listTop.Count / 2-1)
                        lList.Add(Math.Abs(listTop[i + 1] +listTop[i]));
                    else
                        lList.Add(Math.Abs(listTop[i + 1] - listTop[i]));
                }
                else if(i==4)
                {
                    lList.Add(Math.Abs(listTop[3] + listTop[listTop.Count - 4 - 1]));
                }
            }
            double wR = 0.5 * D - pileParameter.concreteProtectLayer - listTop[0];
            //1
            RebarPLPloter.CreateLineArrowDBNew(db, ref ext, M1.C3D(-0.5 * D + pileParameter.concreteProtectLayer+wR, -SheetLength * scale / 2 - 800 - 100 * 8), ArrowDirection.West, new List<double>(), lList, "1", scale, true, 4);
            RebarPLPloter.CreateLineArrowDBNew(db, ref ext, M1.C3D(-0.5 * D + pileParameter.concreteProtectLayer + wR, -50 * 10 - 200 * 10 - 15 * scale), ArrowDirection.West, new List<double>(), lList, "1", scale, true, 4);
            #endregion
            #region  标注
            //顶部标注
            DimPloter.DimRot(db, M1.C3D(-0.5 * D), M1.C3D(-0.5 * D,20*10), M1.C3D(-0.5 * D-5*scale), ref ext, 90, scale, "" ,Unit.Millimeter, Unit.Centimeter);
            DimPloter.DimRotated(db, ref ext, M1.C3D(-0.5 * D, 20 * 10), M1.C3D(-0.5 * D, 20 * 10+tH), M1.C3D(-0.5 * D - 5 * scale), 90, scale, Unit.Millimeter, Unit.Centimeter, "","",1);
            DimPloter.DimRot(db,  M1.C3D(-0.5 * D), M1.C3D(-0.5 * D, 20 * 10 + tH), M1.C3D(-0.5 * D - 10 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Centimeter);
            //左侧
            double H1 = -SheetLength * scale / 2 - 800 - 100 * 8;         
            double H2 = -SheetLength * scale / 2 - 800 - SheetLength * scale * 0.5+bH;
            double H3 = H2 - 1000;
            double H4 = H3 -20*10;
            DimPloter.DimRot(db,  M1.C3D(-0.5 * D), M1.C3D(-0.5 * D, H1), M1.C3D(-0.5 * D - 5 * scale), ref ext, 90, scale, (pileParameter.pile_length - pileParameter.top_encryption_length - pileParameter.bottom_encryption_length - 100 - 20).ToString(), Unit.Millimeter, Unit.Centimeter);
            DimPloter.DimRot(db,  M1.C3D(-0.5 * D, H1), M1.C3D(-0.5 * D, H2), M1.C3D(-0.5 * D - 5 * scale), ref ext, 90, scale, (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length).ToString(), Unit.Millimeter, Unit.Centimeter);
            DimPloter.DimRot(db,  M1.C3D(-0.5 * D,H2), M1.C3D(-0.5 * D, H3), M1.C3D(-0.5 * D - 5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Centimeter);
            DimPloter.DimRot(db,  M1.C3D(-0.5 * D,H3), M1.C3D(-0.5 * D, H4), M1.C3D(-0.5 * D - 5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Centimeter);
            DimPloter.DimRot(db,  M1.C3D(-0.5 * D), M1.C3D(-0.5 * D, H4), M1.C3D(-0.5 * D - 10 * scale), ref ext, 90, scale ,pileParameter.pile_length.ToString(), Unit.Millimeter, Unit.Centimeter);

            //右侧
            DimPloter.DimRot(db,  M1.C3D(0.5 * D), M1.C3D(0.5 * D, 15 * 10), M1.C3D(0.5 * D + 5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Centimeter);
            DimPloter.DimRot(db,  M1.C3D(0.5 * D), M1.C3D(0.5 * D, -50 * 10), M1.C3D(0.5 * D +5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Centimeter);
            DimPloter.DimRot(db,  M1.C3D(0.5 * D, -50 * 10), M1.C3D(0.5 * D, -50 * 10 -200*10), M1.C3D(0.5 * D +5 * scale), ref ext, 90, scale, "", Unit.Millimeter, Unit.Centimeter);
          
            DimPloter.DimRotated(db, ref ext, PtBt.C3D(-0.5 * D, -SheetLength * scale * 0.5 - 20 * 10), PtBt.C3D(0.5 * D, -SheetLength * scale * 0.5 - 20 * 10), PtBt.C3D(0.5 * D, -SheetLength * scale * 0.5 - 20 * 10-5*scale ), 0, scale, Unit.Millimeter, Unit.Centimeter, "", "D");
           


            #endregion

            //PLPloter.CreateReinforcedCageTopHalf(db, ref ext, M1, D / 2, 20, SheetLength * scale / 2, scale);

        }

        private void PlotLPile(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);

            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -5 * scale);
            double SheetLength = 297;
            if (Extensions.curMapSheet == "A3")
                SheetLength = 297 - 10 - 20 - 70;
            else
                SheetLength = 594 - 10 - 30 - 90;
            #region  绘制
            Point2d ptTopEnd = new Point2d();
            SteelBar.CreatePartSteelBar(db, ref ext,out ptTopEnd, M1.C2D(0, 0), D * 0.5 - pileParameter.concreteProtectLayer, SheetLength*scale / 5, 100, scale,true);
          
            Point2d ptBottomStart = ptTopEnd.C2D(0,-800);
            RebarPLPloter.CreateBreakLine(db, ref ext, ptTopEnd, ptBottomStart, scale);
            SteelBar.CreateChangePartSteelBar(db, ref ext, ptBottomStart, D * 0.5 - pileParameter.concreteProtectLayer, SheetLength * scale / 5, 100, scale, 1000,100);
            #endregion
            #region  编号
            System.Data.DataRow[] drs = dtRebar.Select("no=5");
            string noS = drs[0]["number"].ToString() + "Ф" + drs[0]["diameter"].ToString();
            string valueS = (double.Parse(drs[0]["length"].ToString()) / 10).ToString();
            RebarDimPloter.RebarWire(db, ref ext, ptBottomStart.C2D((D * 0.5 - pileParameter.concreteProtectLayer) *0.5, 0), noS, valueS, 5,
               GeTools.DegreeToRadian(0), Extensions.curFont, scale);
            #endregion
            #region  标注
            DimPloter.DimRotated(db, ref ext, M1.C3D(-(D * 0.5 - pileParameter.concreteProtectLayer), 0), M1.C3D(D * 0.5 - pileParameter.concreteProtectLayer, 0), insertPoint.C3D(0, 0), 0, scale, Unit.Millimeter, Unit.Centimeter, "", "D");            
            DimPloter.DimRotated(db, ref ext, ptBottomStart.C3D(-(D * 0.5 - pileParameter.concreteProtectLayer) +100, -SheetLength * scale / 5), ptBottomStart.C3D(D * 0.5 - pileParameter.concreteProtectLayer - 100, -SheetLength * scale / 5), ptBottomStart.C3D(-0.5 * D + 75 + 10, -SheetLength * scale / 5 -5*scale), 0, scale, Unit.Millimeter, Unit.Centimeter, "", "D");

            //右侧
            Point3d ptS = ptBottomStart.C3D(0.5 * D, -(((SheetLength * scale / 5-1000)/100)-1)*100-50);
            DimPloter.DimRotated(db, ref ext, M1.C3D(0.5 * D), ptS, M1.C3D(0.5 * D + 18 * scale), 90, scale, Unit.Millimeter, Unit.Centimeter, (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length).ToString());
            DimPloter.DimRotated(db, ref ext, ptS, ptS.C3D(0, -(1000/150)*150), M1.C3D(0.5 * D + 18 * scale), 90, scale, Unit.Millimeter, Unit.Centimeter, "","",150);
            DimPloter.DimRotated(db, ref ext, ptS.C3D(0, -1000), ptS.C3D(0, -(1000 / 150) * 150), M1.C3D(0.5 * D + 18 * scale), 90, scale, Unit.Millimeter, Unit.Centimeter);
            #endregion
        }

        private void PlotCPile(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);

            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -25 * scale);

            //PLPloter.AddPloy4(db, ref ext, M1, 0.5 * D, 0.5 * D, D);
            double dRSpiral = GeneralRebar.outerDia[pileParameter.spiral_reinforcement_diameter];
            double dRC = GeneralRebar.outerDia[pileParameter.outer_strengthen_reinforcement_diameter];
            double dRMain = GeneralRebar.outerDia[pileParameter.main_reinforcement_diameter];
            double cover = pileParameter.concreteProtectLayer;
            // 平面图
            RebarPLPloter.CreateFacadeReinforcementCage(db, ref ext, M1.C3D(), D*0.5, D * 0.5 - cover- dRSpiral, D * 0.5 - dRSpiral - cover- dRMain- dRC, pileParameter.main_reinforcement_number, "1", "2", "3",  scale, dRMain);
            System.Data.DataRow[] drs = dtRebar.Select("no=3");
            string noS = drs[0]["number"].ToString() + "Ф" + drs[0]["diameter"].ToString();
            string valueS = (double.Parse(drs[0]["length"].ToString()) / 10).ToString();
            string rS = (double.Parse(drs[0]["diameter"].ToString()) / 10).ToString();
            // 三角撑
            RebarPLPloter.CreatePileTriangleTie(db, ref ext, M1.C3D(D*2), D * 0.5 - cover - dRSpiral, noS, valueS, 3, scale,true, true, rS);
            drs = dtRebar.Select("no=4");
            noS = drs[0]["number"].ToString() + "Ф" + drs[0]["diameter"].ToString();
            valueS = (double.Parse(drs[0]["length"].ToString()) / 10).ToString();
            rS = (double.Parse(drs[0]["diameter"].ToString()) / 10).ToString();
            // 顶面
            RebarPLPloter.CreatePileTriangleTie(db, ref ext, M1.C3D(D * 4), D * 0.5 - cover - dRSpiral, noS, valueS, 4, scale,false,true, rS);
            drs = dtRebar.Select("no=6");
           
            if (drs.Length > 0)
            {
                noS = drs[0]["number"].ToString() + "Ф" + drs[0]["diameter"].ToString();
                valueS = (double.Parse(drs[0]["length"].ToString()) / 10).ToString();
                // 三角撑
                RebarPLPloter.CreatePileTriangleTie(db, ref ext, M1.C3D(0, -D * 2), D / 2, noS, valueS, 6, scale, false, false);

                drs = dtRebar.Select("no=2");
                noS = drs[0]["number"].ToString() + "Ф" + drs[0]["diameter"].ToString();
                valueS = (double.Parse(drs[0]["length"].ToString()) / 10).ToString();
                RebarPLPloter.CreatePileReber(db, ref ext, M1.C3D(0, -D * 2.5 - 10 * scale), D / 2, noS, valueS, 2, scale, false, false);
            }
            else
            {
                drs = dtRebar.Select("no=2");
                noS = drs[0]["number"].ToString() + "Ф" + drs[0]["diameter"].ToString();
                valueS = (double.Parse(drs[0]["length"].ToString()) / 10).ToString();
                RebarPLPloter.CreatePileReber(db, ref ext, M1.C3D(0, -D * 1.5 - 10 * scale), D / 2, noS, valueS, 2, scale, false, false);
            }
        }

        public void RendeDetail(ref Database db, Point2d insertPoint, out Extents2d ext,
       System.Data.DataTable dt1, System.Data.DataTable dt2, double scale = 50)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -2 * scale);

            // 绘制表格
            List<string> list = new List<string>();
            list.Add("编号");
            list.Add("直径\\P(mm)");
            //list.Add("大样");
            list.Add("单根长\\P(cm)");
            list.Add("根数");
            list.Add("总长\\P(m)");
            list.Add("单位重\\P(kg/m)");
            list.Add("总重\\P(kg)");
            //list.Add("小计(kg)");
            double height = 0;
            double width = 0;
            ModelTablePloter.DrawCapRebarTable(db, ref ext, M1.C3D(), dt1, list, dt1.Rows.Count + 1, list.Count, ref height, ref width, Extensions.curFont, scale, false);
            double ActualWidth = 0, ActualHeight = 0;
            MText txt = TextPloter.GetTextActualWidth(db, "桩基钢筋明细表", scale,out ActualWidth,out ActualHeight, 5);
            TextPloter.AddMText(db,M1.C3D((width - ActualWidth) / 2,ActualHeight + scale * 2), ref ext, "桩基钢筋明细表", scale, 5, ActualWidth+2*scale, Extensions.curFont);

            List<string> list1 = new List<string>();
            list1.Add("名称及规格");
            list1.Add("名称及规格");
            list1.Add("单位");
            list1.Add("总重");
            list1.Add("合计");
            double height1 = 0;
            double width1 = 0;
            txt = TextPloter.GetTextActualWidth(db, "桩基材料数量表(共" + 4 + "根)", scale, out ActualWidth, out ActualHeight, 5);
            ModelTablePloter.DrawCapMaterialsTable(db, ref ext, M1.C3D(0, -height - ActualHeight * 3), dt2, list1, dt2.Rows.Count + 1, list1.Count, ref height1, ref width1, Extensions.curFont, scale);
            TextPloter.AddMText(db, M1.C3D((width1 - ActualWidth) / 2, -height - ActualHeight * 2 + scale * 2), ref ext, "桩基材料数量表(共" + 4 + "根)", scale, 5, ActualWidth + 2 * scale, Extensions.curFont);

            // 文字
            string text = "注:";
            Point3d p1 = M1.C3D( width1 + scale * 5, -height - ActualHeight * 3);
            TextPloter.AddMText(db, p1, ref ext, text, scale, 3,3*scale, Extensions.curFont);

            text = @"1.本图尺寸除钢筋直径以毫米计外，均会以厘米为单位。
2.N1号主筋采用直螺纹钢筋连接器连接。
3.绑扎铁丝按钢筋总重量的0.5％计。
4.钢筋笼外侧钢筋N5采用混凝土垫块定位，以保证混凝土保护层厚度。
5.为确保桩基混凝土浇筑质量，应对每一根桩基进行超声波检测，4根声测管设于钢筋笼内侧，沿周边等距布置，声测管长度为（桩长+0.7）m。
6.桩基钢筋构造处理应注意防雷接地预埋要求。
7.本图适用于XX号墩。";
            Point3d p2 = M1.C3D(width1 + scale * 5, -height - ActualHeight * 3-4.5*scale);
            TextPloter.AddMText(db,p2, ref ext, text, scale, 3,80*scale, Extensions.curFont);
        }

        public override DBObjectCollection Render()
        {
            DBObjectCollection ret=new DBObjectCollection();

            Circle a = new Circle(Point3d.Origin, Vector3d.ZAxis, 100);
            Circle a1 = new Circle(Point3d.Origin, Vector3d.ZAxis, 100);
            Circle a2 = new Circle(Point3d.Origin, Vector3d.ZAxis, 100);
            Circle a3 = new Circle(Point3d.Origin, Vector3d.ZAxis, 100);

            ret.Add(a);

            ret.Add(a1);

            return ret;            
        }
    }



}
